< previous page page_373 next page >

Page 373
This routine initializes the database and Recordset name variables and then creates the related data objects. Performing this step is similar to setting the DatabaseName, RecordSource, and RecordsetType properties of the data control.
You need to create a Sub procedure to handle the process of reading the current record and loading the data into the form controls. Create a Private Sub procedure called ReadRow and then add the following code to the routine:
Public Sub ReadRow()
    '
    ' fill controls with current value
    '
    Label1.Caption = rs.Fields(0)
    Label2.Caption = rs.Fields(1)
    '
End Sub
This routine copies the first column in the current row of the Recordset to the first form control and then copies the second column of the Recordset to the second form control.
You need to create code for each of the four command buttons on the form. Each button needs to perform two tasks:
· Reposition the pointer as requested
· Read the data from the new current row
The four code pieces in Listing 10.3 do these tasks. Enter the code in that corresponds to the command button into the Click event of that command button. For example, enter rs.MoveFirst and ReadRow into the Click event of the cmdMoveFirst command button. Then enter rs.MoveLast and ReadRow into the cmdMoveLast command button, and so on.
Type.gifListing 10.3. Coding the cmdMove events.
Private Sub cmdMoveFirst_Click()
    '
    rs.MoveFirst
    ReadRow
    '
End Sub

Private Sub cmdMoveLast_Click()
    '
    rs.MoveLast
    ReadRow
    '
End Sub

Private Sub cmdMoveNext_Click()
    '
continues

 
< previous page page_373 next page >

If you like this book, buy it!